#ifndef PARKING_SURVEILLANCE_H
#define PARKING_SURVEILLANCE_H

#include <QWidget>
#include <QLabel>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QImage>
#include <QBuffer>
#include <QTimer>

namespace Ui {
class Parking_Surveillance;
}

class Parking_Surveillance : public QWidget
{
    Q_OBJECT

public:
    explicit Parking_Surveillance(QWidget *parent = 0);
    ~Parking_Surveillance();

public slots:
    void dataUpSlot(const QByteArray& msg);
    void setConnectedState(bool connected);

private slots:
    void on_pushButton_clicked();
    void on_pushButton_2_clicked();
    void on_pushButton_3_clicked();
    void onStreamReadyRead();
    void onStreamFinished();
    void onStreamError(QNetworkReply::NetworkError code);
    void onTimeout();
    void processFrameBuffer();  // 新增：处理帧缓冲区的函数

protected:
    void resizeEvent(QResizeEvent *event) override;

private:
    Ui::Parking_Surveillance *ui;
    bool isConnected;
    QLabel *overlayLabel;

    void createOverlay();
    void destroyOverlay();
    QNetworkAccessManager *networkManager;
    QNetworkReply *streamReply;
    QBuffer *imageBuffer;
    bool isStreaming;
    QString serverUrl;
    QTimer *timeoutTimer;
    QTimer *frameTimer;         // 新增：帧率控制计时器
    QByteArray frameData;       // 新增：帧数据缓冲区
    QString screenshotPath;     // 新增：截图保存路径
};

#endif // PARKING_SURVEILLANCE_H
